$(function () {
    // 获取最近5条工作
    var pageNum = 1;
    var pageSize = 5;
    var html = "";
    $.ajax({
        type: "get",
        url: "/work/getJobList?pageNum=" + pageNum + "&pageSize=" + pageSize,
        dataType: "json",
        success: function (result) {
            html = generateHtml(result);
            var recent_obj = $("#recent-job-item-div");
            recent_obj.html("");
            recent_obj.append(html);
        },
        error: function () {
            $("#warning-fade").html("服务请求失败！");
            $("#myModal").modal();
        }
    });

    function generateHtml(result) {
        html = "";
        $.each(result.data.data, function (i, item) {
            var li = '<div class="job-box bg-white overflow-hidden border rounded mt-4 position-relative overflow-hidden">' +
                '<div class="lable text-center pt-2 pb-2">' +
                '<ul class="list-unstyled best text-white mb-0 text-uppercase">' +
                '<li class="list-inline-item"><i class="mdi mdi-star"></i></li>' +
                '</ul>' +
                '</div>' +
                '<div class="p-4">' +
                '<div class="row align-items-center">' +
                '<div class="col-md-2">' +
                '<div class="mo-mb-2">' +
                '<img src="" alt="" class="img-fluid mx-auto d-block">' +
                '</div>' +
                '</div>' +
                '<div class="col-md-4">' +
                '<div>' +
                '<h5 class="f-18"><a href="job-details.html?jobId=' + item.jobId + '" class="text-dark">' + item.jobTitle + '</a></h5>' +
                '</div>' +
                '</div>' +
                '<div class="col-md-3">' +
                '<div>' +
                '<p class="text-muted mb-0 mo-mb-2"><span class="text-dark">单位: </span>' +
                item.department +
                '</p>' +
                '</div>' +
                '</div>' +
                '<div class="col-md-3">' +
                '<div>' +
                '<p class="text-muted mb-0 mo-mb-2"><span class="text-dark">电话: </span>' +
                item.phoneNumber +
                '</p>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '<div class="p-3 bg-light">' +
                '<div class="row">' +
                '<div class="col-md-10">' +
                '<div>' +
                '<p class="text-muted mb-0 mo-mb-2"><span class="text-dark">发布时间 :</span>' +
                item.gmtCreate +
                '</p>' +
                '</div>' +
                '</div>' +
                '<div class="col-md-2">' +
                '<div>' +
                '<a href="javascript:void(0);" onclick="apply_job(' + item.jobId + ')" class="text-primary">申请' +
                '<i class="mdi mdi-chevron-double-right"></i>' +
                '</a>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>' +
                '</div>';
            html = html + li;
        });
        return html;
    }

    // 获取推荐的5条数据
    $.ajax({
        type: "get",
        url: "/work/getJobList?pageNum=" + pageNum + "&pageSize=" + pageSize + "&isRecommend=1",
        dataType: "json",
        success: function (result) {
            generateHtml(result);
            html = generateHtml(result);
            var recommend_obj = $("#recommend-job-item-div");
            recommend_obj.html("");
            recommend_obj.append(html);
        },
        error: function () {
            $("#warning-fade").html("服务请求失败！");
            $("#myModal").modal();
        }
    });

    $("#search-button").click(function () {
        var jobKeyword = $("#search-keyword").val();
        var departKeyword = $("#search-company").val();
        location.href = "job-list.html?jobKeyword=" + jobKeyword + "&departKeyword=" + departKeyword;
    });
});